package morning.cat.coding;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 * XXX
 *
 * @author mengzhang6
 * @date 2018/12/12 18:20
 */
public class CodingTest {

    String msg = "这是一个中文字符串\r\n你好世界";

    @Test
    public void test1() throws IOException {

        File file = new File("F:\\1001.txt");
        FileUtils.writeByteArrayToFile(file,msg.getBytes());

        String read = FileUtils.readFileToString(file, Charset.defaultCharset());
        System.out.println(read);
    }


    @Test
    public void test2() throws IOException {
        File file = new File("F:\\1002.txt");
        FileUtils.writeByteArrayToFile(file,msg.getBytes("UTF-8"));

        String read = FileUtils.readFileToString(file, Charset.forName("UTF-8"));
        System.out.println(read);
    }

    @Test
    public void test3() throws IOException {
        File file = new File("F:\\1003.txt");
        FileUtils.writeByteArrayToFile(file,msg.getBytes("GBK"));

        String read = FileUtils.readFileToString(file, Charset.forName("GBK"));
        System.out.println(read);
    }

    @Test
    public void test4() throws IOException {
        File file = new File("F:\\1004.txt");
        FileUtils.writeByteArrayToFile(file,msg.getBytes("GB2312"));

        String read = FileUtils.readFileToString(file, Charset.forName("GB2312"));
        System.out.println(read);
    }

    @Test
    public void test5() throws IOException {
        File file = new File("F:\\rBC_nVvFRVOAWVLlAAQoIQkCZ5w24.txti");
        String read = FileUtils.readFileToString(file, Charset.forName("GBK"));
        System.out.println(read);
    }

}
